package o;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.hms.aaid.HmsInstanceId;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.aaid.entity.AAIDResult;
import o.dky.j;

public class ctw {
    private static String ˋ;

    public static void ॱ() {
        if (TextUtils.isEmpty(ˋ)) {
            HmsInstanceId.getInstance(ॱॱ()).getAAID().ˏ(new fjp<AAIDResult>() {
                public /* synthetic */ void ˎ(Object obj) {
                    ˏ((AAIDResult) obj);
                }

                public void ˏ(AAIDResult aAIDResult) {
                    ctw.ˋ = aAIDResult.getId();
                    Logger.ˏ("PushTokenManager", "getAaid success.");
                    ctw.ˋ();
                }
            }).ˋ(new fjr() {
                public void ˎ(Exception exception) {
                    Logger.e("PushTokenManager", "getAAID failed");
                }
            });
            return;
        }
        Logger.ˏ("PushTokenManager", "aaid already exist.");
        ˋ();
    }

    public static void ॱ(String str) {
        ˎ();
        Context ˋ = ContentManager.getInstant().getContext();
        Intent intent = new Intent();
        intent.setAction("android.huawei.appmarket.pushdeal.ontokennew");
        intent.setPackage(ˋ.getPackageName());
        Bundle bundle = new Bundle();
        bundle.putString("token", str);
        intent.putExtras(bundle);
        ˋ.sendBroadcast(intent, cud.ˊ);
    }

    private static void ˋ() {
        dmq.ˏ.ॱ(new dmi() {
            public void run() {
                try {
                    Context ˊ = ctw.ॱॱ();
                    Object token = HmsInstanceId.getInstance(ˊ).getToken(ˊ.getString(j.ͺॱ), AaidIdConstant.DEFAULT_SCOPE_TYPE);
                    if (TextUtils.isEmpty(token)) {
                        Logger.ˎ("PushTokenManager", "startTokenThread getToken empty.");
                        return;
                    }
                    Logger.ˎ("PushTokenManager", "startTokenThread getToken success.");
                    ctw.ॱ(token);
                } catch (Throwable e) {
                    Logger.ˋ("PushTokenManager", "getToken faile.", e);
                }
            }
        });
    }

    private static void ˎ() {
        if (!eqp.ʼ()) {
            euf.ˎ().ˎ(true);
            eua.ˏ().ˋ("oversea_push_agreement", true);
            eua.ˏ().ˊ("personal.push.notice.status", 1);
        }
    }

    private static Context ॱॱ() {
        Context ʻॱ = AbstractBaseActivity.ʻॱ();
        if (ʻॱ == null) {
            return ContentManager.getInstant().getContext();
        }
        return ʻॱ;
    }
}
